package com.kingwan.freemarkword.controller;

import com.kingwan.freemarkword.pojo.BaseResume;
import com.kingwan.freemarkword.service.DownloadService;
import com.kingwan.freemarkword.utils.ImageUtil;
import com.kingwan.freemarkword.utils.WordExportUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by kingwan on 2020/12/6.
 * 说明：
 */
@Controller
public class ResumeController {
    @Autowired
    DownloadService downloadService;

    @PostMapping("/createResume")
    @ResponseBody
    public String createResume(BaseResume baseResume){
        System.out.println(baseResume);
        //信息验证
        //组装模板
        String imageStr = ImageUtil.getImageStr(baseResume.getRsPicUrl());
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("Resume",baseResume);
        dataMap.put("RsImage", imageStr);
//        dataMap.put("RsName", baseResume.getRsName());
//        dataMap.put("RsBirthday", baseResume.getRsBirthday());
//        dataMap.put("RsTelephone", baseResume.getRsTelephone());
//        dataMap.put("RsSkills", baseResume.getRsSkills());
//        dataMap.put("RsImage", baseResume.getRsPicUrl());
//        dataMap.put("RsAddress", baseResume.getRsAddress());
//        dataMap.put("RsEducation", baseResume.getRsEducation());
//        dataMap.put("RsNative", baseResume.getRsNative());
//        dataMap.put("RsPosition", baseResume.getRsPosition());
        WordExportUtil emw = new WordExportUtil();
        emw.createWord(dataMap, "resume-white.ftl", "doc/resume.doc");
        //保存输出
        return "success";
    }

    @RequestMapping("/downloadResume")
    @ResponseBody
    public void downloadResume(String name, HttpServletResponse response) throws Exception {
        downloadService.docDownloadService("resume.doc",response);
    }
}
